home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Libraries / tcl7.4b3 / doc / DString.3 < prev    next >
Encoding:
Text File  |  1995-02-22  |  5.7 KB  |  156 lines

  1. '\"
  2. '\" Copyright (c) 1993 The Regents of the University of California.
  3. '\" Copyright (c) 1994-1995 Sun Microsystems, Inc.
  4. '\"
  5. '\" See the file "license.terms" for information on usage and redistribution
  6. '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  7. '\" 
  8. '\" @(#) DString.3 1.15 95/02/22 14:37:16
  9. '\" 
  10. .so man.macros
  11. .HS Tcl_DString tclc 7.4
  12. .BS
  13. .SH NAME
  14. .na
  15. Tcl_DStringInit, Tcl_DStringAppend, Tcl_DStringAppendElement, Tcl_DStringStartSublist, Tcl_DStringEndSublist, Tcl_DStringLength, Tcl_DStringValue, Tcl_DStringSetLength, Tcl_DStringFree, Tcl_DStringResult, Tcl_DStringGetResult \- manipulate dynamic strings
  16. .ad
  17. .SH SYNOPSIS
  18. .nf
  19. \fB#include <tcl.h>\fR
  20. .sp
  21. \fBTcl_DStringInit\fR(\fIdsPtr\fR)
  22. .sp
  23. char *
  24. \fBTcl_DStringAppend\fR(\fIdsPtr, string, length\fR)
  25. .sp
  26. char *
  27. \fBTcl_DStringAppendElement\fR(\fIdsPtr, string\fR)
  28. .sp
  29. \fBTcl_DStringStartSublist\fR(\fIdsPtr\fR)
  30. .sp
  31. \fBTcl_DStringEndSublist\fR(\fIdsPtr\fR)
  32. .sp
  33. int
  34. \fBTcl_DStringLength\fR(\fIdsPtr\fR)
  35. .sp
  36. char *
  37. \fBTcl_DStringValue\fR(\fIdsPtr\fR)
  38. .sp
  39. .VS
  40. \fBTcl_DStringSetLength\fR(\fIdsPtr, newLength\fR)
  41. .VE
  42. .sp
  43. \fBTcl_DStringFree\fR(\fIdsPtr\fR)
  44. .sp
  45. \fBTcl_DStringResult\fR(\fIinterp, dsPtr\fR)
  46. .sp
  47. .VS
  48. \fBTcl_DStringGetResult\fR(\fIinterp, dsPtr\fR)
  49. .VE
  50. .SH ARGUMENTS
  51. .AS Tcl_DString newLength
  52. .AP Tcl_DString *dsPtr in/out
  53. Pointer to structure that is used to manage a dynamic string.
  54. .AP char *string in
  55. Pointer to characters to add to dynamic string.
  56. .AP int length in
  57. Number of characters from string to add to dynamic string.  If -1,
  58. add all characters up to null terminating character.
  59. .AP int newLength in
  60. New length for dynamic string, not including null terminating
  61. character.
  62. .AP Tcl_Interp *interp in/out
  63. Interpreter whose result is to be set from or moved to the
  64. dynamic string.
  65. .BE
  66.  
  67. .SH DESCRIPTION
  68. .PP
  69. Dynamic strings provide a mechanism for building up arbitrarily long
  70. strings by gradually appending information.  If the dynamic string is
  71. short then there will be no memory allocation overhead;  as the string
  72. gets larger, additional space will be allocated as needed.
  73. .PP
  74. \fBTcl_DStringInit\fR initializes a dynamic string to zero length.
  75. The Tcl_DString structure must have been allocated by the caller.
  76. No assumptions are made about the current state of the structure;
  77. anything already in it is discarded.
  78. If the structure has been used previously, \fBTcl_DStringFree\fR should
  79. be called first to free up any memory allocated for the old
  80. string.
  81. .PP
  82. \fBTcl_DStringAppend\fR adds new information to a dynamic string,
  83. allocating more memory for the string if needed.
  84. If \fIlength\fR is less than zero then everything in \fIstring\fR
  85. is appended to the dynamic string;  otherwise \fIlength\fR
  86. specifies the number of bytes to append.
  87. \fBTcl_DStringAppend\fR returns a pointer to the characters of
  88. the new string.  The string can also be retrieved from the
  89. \fIstring\fR field of the Tcl_DString structure.
  90. .PP
  91. \fBTcl_DStringAppendElement\fR is similar to \fBTcl_DStringAppend\fR
  92. except that it doesn't take a \fIlength\fR argument (it appends
  93. all of \fIstring\fR) and it converts the string to a proper list element
  94. before appending.
  95. \fBTcl_DStringAppendElement\fR adds a separator space before the
  96. new list element unless the new list element is the first in a
  97. list or sub-list (i.e. either the current string is empty, or it
  98. contains the single character ``{'', or the last two characters of
  99. the current string are `` {'').
  100. \fBTcl_DStringAppendElement\fR returns a pointer to the
  101. characters of the new string.
  102. .PP
  103. \fBTcl_DStringStartSublist\fR and \fBTcl_DStringEndSublist\fR can be
  104. used to create nested lists.
  105. To append a list element that is itself a sublist, first
  106. call \fBTcl_DStringStartSublist\fR, then call \fBTcl_DStringAppendElement\fR
  107. for each of the elements in the sublist, then call
  108. \fBTcl_DStringEndSublist\fR to end the sublist.
  109. \fBTcl_DStringStartSublist\fR appends a space character if needed,
  110. followed by an open brace;  \fBTcl_DStringEndSublist\fR appends
  111. a close brace.
  112. Lists can be nested to any depth.
  113. .PP
  114. \fBTcl_DStringLength\fR is a macro that returns the current length
  115. of a dynamic string (not including the terminating null character).
  116. \fBTcl_DStringValue\fR is a  macro that returns a pointer to the
  117. current contents of a dynamic string.
  118. .PP
  119. .VS
  120. .PP
  121. \fBTcl_DStringSetLength\fR changes the length of a dynamic string.
  122. If \fInewLength\fR is less than the string's current length, then
  123. the string is truncated.
  124. If \fInewLength\fR is greater than the string's current length,
  125. then the string will become longer and new space will be allocated
  126. for the string if needed.
  127. However, \fBTcl_DStringSetLength\fR will not initialize the new
  128. space except to provide a terminating null character;  it is up to the
  129. caller to fill in the new space.
  130. \fBTcl_DStringSetLength\fR does not free up the string's storage space
  131. even if the string is truncated to zero length, so \fBTcl_DStringFree\fR
  132. will still need to be called.
  133. .VE
  134. .PP
  135. \fBTcl_DStringFree\fR should be called when you're finished using
  136. the string.  It frees up any memory that was allocated for the string
  137. and reinitializes the string's value to an empty string.
  138. .PP
  139. \fBTcl_DStringResult\fR sets the result of \fIinterp\fR to the value of
  140. the dynamic string given by \fIdsPtr\fR.  It does this by moving
  141. a pointer from \fIdsPtr\fR to \fIinterp->result\fR.
  142. This saves the cost of allocating new memory and copying the string.
  143. \fBTcl_DStringResult\fR also reinitializes the dynamic string to
  144. an empty string.
  145. .PP
  146. .VS
  147. \fBTcl_DStringGetResult\fR does the opposite of \fBTcl_DStringResult\fR.
  148. It sets the value of \fIdsPtr\fR to the result of \fIinterp\fR and
  149. it clears \fIinterp\fR's result.
  150. If possible it does this by moving a pointer rather than by copying
  151. the string.
  152. .VE
  153.  
  154. .SH KEYWORDS
  155. append, dynamic string, free, result
  156.